package test.study.kits.excel.easyexcel._2_write;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Builder;
import lombok.Data;
import org.junit.Test;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class _2_indexOrName_write_Test {

    private String outputFile = "d:/indexOrName_write_output.xlsx";

    @Test
    public void test() {
        //
        EasyExcel.write(outputFile, IndexData.class)
                .sheet()
                .doWrite(dataLt(10));
    }

    private List<IndexData> dataLt(int size) {
        return IntStream.range(0, size)
                .mapToObj(e -> IndexData.builder()
                        .name("wangzh")
                        .age(23)
                        .sex("男")
                        .build()).collect(Collectors.toList());
    }

    @Builder
    @Data
    private static class IndexData {
        @ExcelProperty(value = "姓名", index = 0)
        private String name;
        @ExcelProperty(value = "年龄", index = 2)
        private Integer age;
        @ExcelProperty(index = 1)
        private String sex;
    }
}
